import plugin from '../../../lib/plugins/plugin.js'
import common from '../../../lib/common/common.js'
import { segment } from "oicq"
import fetch from "node-fetch"
import fs from 'node:fs'
import path from 'path'
import lodash from 'lodash'
import { createRequire } from "module"

const require = createRequire(import.meta.url)
const glt = 'https://gitee.com/xingdonglcy/mingchao-img/raw/master/'

export class cxhelp extends plugin {
    constructor () {
        super({
            /** 功能名称 */
            name: '鸣潮查询帮助',
            /** 功能描述 */
            dsc: '查看鸣潮图鉴、材料',
            /** https://oicqjs.github.io/oicq/#events */
            event: 'message',
            /** 优先级，数字越小等级越高 */
            priority: 1,
            rule: [
                {
                    /** 命令正则匹配 */
                    reg: '#?鸣潮公告$',
                    /** 执行方法 */
                    fnc: 'mcgg'
                },
                {
                    /** 命令正则匹配 */
                    reg: '#鸣潮?(.*)(攻略|攻略2)$',
                    /** 执行方法 */
                    fnc: 'mcgl'
                }
            ]
        });
    }
    async mcgg(e){
        //e.msg 用户的命令消息
        console.log("用户命令：", e.msg);
        //执行的逻辑功能
        let url = `https://prod-alicdn-community.kurobbs.com/forum/8b17a8f0673c4eb9a86dbf57aa4eac8d20240522.jpg`;
        let res = await fetch(url).catch((err) => logger.error(err));
        
        let msg = [segment.image(res.url)];

        //发送消息
        e.reply(msg,true);

        return true; //返回true 阻挡消息不再往下
    }
    async mcgl(e) {
        const messageText = e.msg
        var reg = new RegExp('#鸣潮?(.*)(攻略|攻略2)$');
        const match = messageText.match(reg);
        let name = match[1];
        let pd = match[2];//后续多攻略需要
        let url = `${glt}攻略/1/${name}.jpg`
        let res = await fetch(url).catch((err) => logger.error(err));
        let msg = [segment.image(res.url)];
        //发送消息
        e.reply(msg,true);
    }
}